<?php

class Grc extends MY_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->service('Service_grc');
    }

    public function index()
    {
        $this->load->model('Model_urls');
        $cond = ['grc' => 0];
        $list = $this->Model_urls->getList(1, $cond, 10, 'ASC');
        foreach ($list as $item) {
            $url = stripos($item['url'], "http") === false ? "http:" . $item['url'] : $item['url'];
            list($flag, $msg) = $this->Service_grc->check($url);
            echo $item['id'] . '|' . $item['url'] ."|{". $msg . '}<br/>' . PHP_EOL;

            $data = ['id'=> $item['id'], 'grc_msg' => $msg];
            if ($flag) {
                $data['grc'] = 1;
                $data['show'] = 1;
            } else {
                $data['grc'] = 2;
                $data['show'] = 0;
            }
            $this->Model_urls->update($data);
        }
    }
}